<template>
    <div class="userinfo">
        <!-- <router-link to="/userinfoone" class="nameinfo">
            <div class="left-box">
                <div class="left">
                    <img v-if="src!=''" :src="src+'?x-oss-process=image/resize,m_fill,h_180,w_180'" alt="">
                    <img v-else src="../../assets/image/default.png" alt="">
                </div>
                <div class="center">
                    <p><span v-if="status=='已认证'">{{name}}</span><span  v-if="status=='未认证'">{{nickname}}</span><span>{{status}}</span></p>
                    <p>{{phone}}</p>
                </div>
            </div>
            <div class="right">
                <i class="iconfont">&#xe871;</i>
            </div>
        </router-link> -->
        <div class="item-lr bd first">
            <div class="left">头像</div>
            <div class="right"><span @click="takephoto()"><img :src="headimgurl+'?x-oss-process=image/resize,m_fill,h_180,w_180'" alt=""></span><i class="iconfont">&#xe871;</i></div>
        </div>
        <router-link to="/userinfoname" class="item-lr bd">
            <div class="left">昵称</div>
            <div class="right"><span>{{nickname}}</span><i class="iconfont">&#xe871;</i></div>
        </router-link>
        <router-link to="/userinfophone" class="item-lr bd">
            <div class="left">手机号</div>
            <div class="right"><span>{{phone}}</span><i class="iconfont">&#xe871;</i></div>
        </router-link>
        <router-link to="/userinfoidcard"  v-if="status=='已认证'" class="item-lr">
            <div class="left">身份认证</div>
            <div class="right"><span class="">{{name}}<i>{{status}}</i></span><i class="iconfont">&#xe871;</i></div>
        </router-link>
        <router-link  v-if="status=='去认证'" to="/idcardtwo" class="item-lr">
            <div class="left">身份认证</div>
            <div class="right"><span style="font-size: 15px;color: #0089FC;" class="">{{status}}</span><i class="iconfont">&#xe871;</i></div>
        </router-link>
        <router-link to="/inviocelist" class="item-lr mt">
            <div class="left">开票记录</div>
            <div class="right"><i class="iconfont">&#xe871;</i></div>
        </router-link>
        <router-link to="/feedback" class="item-lr mt bd">
            <div class="left">意见反馈</div>
            <div class="right"><i class="iconfont">&#xe871;</i></div>
        </router-link>
        <router-link to="" class="item-lr">
            <div class="left">关于宜住人生</div>
            <div class="right"><i class="iconfont">&#xe871;</i></div>
        </router-link>
    </div>
</template>

<script>
import axios from 'axios';
import Wx from 'weixin-js-sdk';
import { MessageBox, Toast, Popup } from 'mint-ui';
export default {
    data () {
        return {
            nickname: '',
            phone: '',
            src: '',
            status: '',
            name: '',
            headimgurl: ''
        }
    },
    created () {
        const vm = this;
        axios.post('/Weixin/Member/memberDetail',{}).then(res=>{
            const data = res.data;
            console.log(data);
            if(data.code==1){
                vm.headimgurl = data.data.headimgurl?data.data.headimgurl:'http://ldfs.oss-cn-shenzhen.aliyuncs.com/e31a349c9b41d978650324d546056413.png';
                vm.nickname= data.data.nickname;
                vm.name= data.data.name;
                vm.phone = data.data.phone;
                vm.src = data.data.headimgurl;
                vm.status = data.data.state==3?'已认证':'去认证';
            }else {
                MessageBox.alert(data.msg)
            }
        }).catch(()=>{
            MessageBox.alert('网络错误');
        })
    },
    mounted() {
        const vm = this;
        let url = window.location.href;
        vm.wxShare(url);
    },
    methods: {
        jump(url){
            const vm = this;
            vm.$router.replace(url)
        },
        takephoto(){
            // const vm = this;
            // vm.headimgurl = 'http://ldfs.oss-cn-shenzhen.aliyuncs.com/14539884e9e259cbd08098b3105028df.jpg';
            const vm = this,
            upload = vm.wxUpload(Wx);
            let ajaxUp = function(id) {
                vm.$axiosPost('/Api/Upload/downloadWxImage', {'media_id': id}).then(json => {
                    vm.sheetVisible = false;
                    // 上传成功，后台不保存，前台更新用户头像
                    if (json.data.code == 1) {
                          vm.headimgurl = json.data.url;
                         vm.updateHeadimg(json.data.url)
                    } else {
                        MessageBox.alert(json.data.msg);
                    }
                }, function() {
                    MessageBox.alert('网络异常，上传失败');
                });
            }
            Wx.ready(function(){
                upload.chooseImg(ajaxUp, 1);
            });
            // vm.updateHeadimg( vm.headimgurl);
        },
        updateHeadimg(url) {
            let data = {
                headimgurl: url
            };
            axios.post('/Weixin/Member/editMember', data).then(json => {
                console.log(json.data)
                if (json.data.code == 1) {
                   this.$toast(json.data.msg);
                }
               
            });
        },
    }
}
</script>


<style>

</style>
